package com.tuanzi.loan.business.service.statistics.impl;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.entity.collaborate.StatCollaborateMarketLogin;
import com.tuanzi.loan.business.repository.statistics.custom.StatMarketLoginCustomRepository;
import com.tuanzi.loan.business.service.statistics.StatMarketLoginService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.statistics.login.StatMarketLoginRequest;
import com.tuanzi.loan.vo.response.statistics.login.StatMarketLoginResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author: chenweijun
 * @Date: 2019/3/6 17:21
 * @Description:
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class StatMarketLoginServiceImpl implements StatMarketLoginService{

    @Autowired
    private StatMarketLoginCustomRepository statMarketLoginCustomRepository;

    @Override
    public Page<StatMarketLoginResponse> list(PageSearcher<StatMarketLoginRequest> pageSearcher) {
        return statMarketLoginCustomRepository.list(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
    }

    @Override
    public List<StatCollaborateMarketLogin> findAllByCreateDateAndChannelIn(List<Integer> channels, Date date) {
        if(channels ==null || channels.size() == 0 || null ==date){
            return Lists.newArrayList();
        }

        return statMarketLoginCustomRepository.findAllByCreateDateAndChannelIn(channels, date);
    }
}
